﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace HelperMethods.Infrastructure
{
    public static class CustomHelpers
    {
        public static MvcHtmlString ListArrayItems(this HtmlHelper html, string[] list)
        {
            TagBuilder tag = new TagBuilder("ul");
            foreach (string str in list)
            {
                TagBuilder itemTag = new TagBuilder("li");
                itemTag.SetInnerText(str); //html encoded
                tag.InnerHtml += itemTag.ToString(); //not encoded

                //AddCssClass
                //MergeAttribute add/replace attribute
            }
            return new MvcHtmlString(tag.ToString());
        }

        /*
         * Return Type: MvcHtmlString -> return not encoded result
         * Return Type: string -> return encoded result
         */
        public static MvcHtmlString DisplayMessage(this HtmlHelper html, string msg)
        {
            //encode the message
            //string msg = html.Encode(msg);
            string result = String.Format("This is the message: <p>{0}</p>", msg);                    
            return new MvcHtmlString(result);
        }
    }
}